﻿using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.OCR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tesseract;
using static Emgu.CV.ML.KNearest;
using Pix = Tesseract.Pix;

namespace EMguConsole.Core
{
    public class FindTesseract
    {
        public static void Find()
        {
            // Tesseract 数据文件路径
            string tessDataPath = @"E:\VS_Code\仪表盘识别\Tesseract\tessdata_fast";

            // 图片文件路径
            string imagePath = @"C:\Users\93143\Desktop\3.jpg";

            using (var engine = new TesseractEngine(tessDataPath, "eng", EngineMode.Default))
            {
                using (var img = Pix.LoadFromFile(imagePath))
                {
                    using (var page = engine.Process(img))
                    {
                        string text = page.GetText();
                        Console.WriteLine("识别结果：");
                        Console.WriteLine(text);
                    }
                }
            }
        }


        public static void Find(byte[] bytes)
        {
            // Tesseract 数据文件路径
            string tessDataPath = @"E:\VS_Code\仪表盘识别\Tesseract\tessdata_fast";

            using (var engine = new TesseractEngine(tessDataPath, "eng", EngineMode.Default))
            {
                using (var img = Pix.LoadFromMemory(bytes))
                {
                    using (var page = engine.Process(img))
                    {
                        string text = page.GetText();
                        Console.WriteLine("识别结果：");
                        Console.WriteLine(text);
                    }
                }
            }
        }
    }
}
